#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm
import time
from collections import deque

# 使用列表原生方法插入元素并计时
lst = []
start_time_lst_insert_head = time.time()
for _ in range(10):
    lst.insert(0, _)
end_time_lst_insert_head = time.time()
head_insert_time_lst = end_time_lst_insert_head - start_time_lst_insert_head

start_time_lst_insert_tail = time.time()
for _ in range(10):
    lst.append(_)
end_time_lst_insert_tail = time.time()
tail_insert_time_lst = end_time_lst_insert_tail - start_time_lst_insert_tail

# 使用deque插入元素并计时
dq = deque()
start_time_dq_insert_head = time.time()
for _ in range(10):
    dq.appendleft(_)
end_time_dq_insert_head = time.time()
head_insert_time_dq = end_time_dq_insert_head - start_time_dq_insert_head

start_time_dq_insert_tail = time.time()
for _ in range(10):
    dq.append(_)
end_time_dq_insert_tail = time.time()
tail_insert_time_dq = end_time_dq_insert_tail - start_time_dq_insert_tail

print(f"头部插入时间差（列表-deque）: {head_insert_time_lst - head_insert_time_dq}")
print(f"尾部插入时间差（列表-deque）: {tail_insert_time_lst - tail_insert_time_dq}")
